  import {
      createBtnHandler
  } from './create';
  import {
      editBtnHandler
  } from './edit';
  import {
      removeBtnHandler
  } from './remove';

  import {
      grid
  } from '../common/grid';
  import {
      editPwd,
      loginOut
  } from '../common/settings';
  $(function () {

      grid();
      window.editPwd = editPwd;
      window.loginOut = loginOut;

      let $table = $('#table').bootstrapTable({
          toolbar: '#toolbar',
          url: GLOBAL_ListUrl,

          sidePagination: "server",
          queryParamsType: '',
          columns: [{
              checkbox: true
          },{
              field: 'cat_name_zh',
              title: '中文分类名',
              sortable: true,
              formatter: function (value, row, index) {
                  if (row.pid > 0) {
                      return `<i class="line"></i>${value}`;
                  }
                  return value;
              }
          }, {
              field: 'cat_name_en',
              title: '英文分类名',
              sortable: true,
              formatter: function (value, row, index) {
                  if (row.pid > 0) {
                      return `<i class="line"></i>${value}`;
                  }
                  return value;
              }
          }, {
              field: 'sort',
              title: '排序',
              sortable: true
          },  {
              field: 'operate',
              title: '操作',
              formatter: function (value, row, index) {
                  return row.pid>0? `
            <a class="section btn-custome" href="${GLOBAL_GoodsUrl}?cat_id=${row.cat_id}" title="查看文章">查看文章</a>`:"";
              }
          }]
      });

      //多选不能编辑,删除
      $table.on('check.bs.table', () => {
          let selectedList = $('#table').bootstrapTable('getSelections');
          if (selectedList.length > 1) {
              $('#editBtn').attr('disabled', 'disabled');
              $('#removeBtn').attr('disabled', 'disabled');
              return;
          }
          $('#editBtn').removeAttr('disabled');
          $('#removeBtn').removeAttr('disabled');
      });
      $table.on('uncheck.bs.table', () => {
          let selectedList = $('#table').bootstrapTable('getSelections');
          if (selectedList.length > 1) {
              $('#editBtn').attr('disabled', 'disabled');
              $('#removeBtn').attr('disabled', 'disabled');
              return;
          }
          $('#editBtn').removeAttr('disabled');
          $('#removeBtn').removeAttr('disabled');
      });
      $table.on('check-all.bs.table', (rows) => {
          $('#editBtn').attr('disabled', 'disabled');
          $('#removeBtn').attr('disabled', 'disabled');
      });
      $table.on('uncheck-all.bs.table', (rows) => {
          $('#editBtn').removeAttr('disabled');
          $('#removeBtn').removeAttr('disabled');
      });


      window.createBtnHandler = createBtnHandler;
      window.editBtnHandler = editBtnHandler;
      window.removeBtnHandler = removeBtnHandler;






  }());